package com.autumn.platform.dao.schema.statement.original;

import org.apache.ibatis.builder.CacheRefResolver;
import org.apache.ibatis.builder.IncompleteElementException;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.session.Configuration;

import com.autumn.platform.dao.schema.parser.SchemaSqlMapperParserDelegate;
import com.autumn.platform.dao.schema.statement.StatementHandlerSupport;

public class CacheRefStatementHandler extends StatementHandlerSupport {

    @Override
    public void handleStatementNode(Configuration configuration, SchemaSqlMapperParserDelegate delegate, XNode node) {
        String namesapce = node.getStringAttribute("namespace");
        MapperBuilderAssistant builder = delegate.getBuilderAssistant();
        configuration.addCacheRef(builder.getCurrentNamespace(), namesapce);
        CacheRefResolver cacheRefResolver = new CacheRefResolver(builder, namesapce);
        try {
            cacheRefResolver.resolveCacheRef();
        } catch (IncompleteElementException e) {
            configuration.addIncompleteCacheRef(cacheRefResolver);
        }
    }
}
